/*
 * @(#)GSProviderDAO.java
 * 
 * Project: BUS
 * 
 * Modify Information:
 * =============================================================================
 * Author          Date         Description
 *  ------------ ---------- ------------------------------------- 
 *  simonyi peng  2006-4-11    创建
 *  Jenny   Li    2006-4-17    添加方法getConfirmableEmergyOrder,tempOrderExeConfirm,tempOrderSubmitToApep,
 *                             delTempOrder,queryTempOrderDetail
 *  Jenny   Li    2006-5-19    修改方法tempOrderExeConfirm                            
 *                             
 * Copyright Notice:
 * =============================================================================
 */
package com.hitrust.gs.business;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import com.hitrust.gs.bean.GSOperatorBean;
import com.hitrust.gs.bean.GSOrderBean;
import com.hitrust.gs.bean.GSOrderDetailBean;
import com.hitrust.gs.bean.GSTempOrderBean;
import com.hitrust.gs.dao.GSDictionaryDAO;
import com.hitrust.gs.dao.GSOrderDAO;
import com.hitrust.gs.dao.GSOrderDetailDAO;
import com.hitrust.gs.dao.GSOrganizationDAO;
import com.hitrust.gs.dao.GSTempOrderDAO;
import com.hitrust.gs.integration.socket.GSClientSocket;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.lib.GSSystemConfigurator;
import com.hitrust.gs.service.GSBaseManager;
import com.hitrust.gs.util.DefineDic;
import com.hitrust.gs.util.ParameterFactory;
import com.hitrust.gs.util.date.DateUtil;
import com.hitrust.gs.util.exception.GSException;
import com.hitrust.gs.util.lang.StringUtils;
import com.hitrust.gs.vo.GSBusEmergencyOrderConfirmDetailVO;
import com.hitrust.gs.vo.GSBusEmergencyOrderConfirmVO;
import com.hitrust.gs.vo.GSBusEmergencyOrderQueryVO;
import com.hitrust.gs.vo.GSOrderTempManufactureVO;
import com.hitrust.gs.vo.GSOrderTempVO;

/**
 * @author simonyi
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class GSTempOrderProcesser {

    public boolean isDeliverGoodsIdExist(String deliverGoodsId) throws GSException {
        GSTempOrderDAO dao = new GSTempOrderDAO();
        return dao.isDeliverGoodsIdExist(deliverGoodsId);
    }

    public Object[] isDeliverGoodsIdExistAndStatus(String deliverGoodsId) throws GSException {
        GSTempOrderDAO dao = new GSTempOrderDAO();
        return dao.isDeliverGoodsIdExistAndStatus(deliverGoodsId);
    }

    public String saveOrder(GSOperatorBean bean, GSOrderTempVO vo, ArrayList ary) throws GSException {
        GSTempOrderDAO dao = new GSTempOrderDAO();
        String orderId = dao.insert(bean, vo, ary);
        return orderId;
    }

    /**
     * 查询一个订单的所有明细，用于订单录入
     * 
     * @param orderId
     * @return
     * @throws GSException
     */
    public ArrayList getOrderDetail_(String orderId) throws GSException {
        ArrayList tList = new ArrayList();
        try {
            GSTempOrderDAO tGSTempOrderDAO = new GSTempOrderDAO();
            // 查询订单明细
            ArrayList tRs = tGSTempOrderDAO.queryOrderDetail_(orderId);
            if (tRs.size() > 0) {
                for (int i = 0; i < tRs.size(); i++) {
                    String[] tStr = new String[27];
                    GSOrderTempManufactureVO tGSOrderManufactureVO = (GSOrderTempManufactureVO) tRs.get(i);
                    // 取出订单包含的产品信息VO对象组成String数组
                    tStr[0] = tGSOrderManufactureVO.orderTempId;
                    tStr[1] = tGSOrderManufactureVO.orderDetailId;
                    tStr[2] = tGSOrderManufactureVO.workcorpId;
                    tStr[3] = tGSOrderManufactureVO.deliverMode;
                    tStr[4] = tGSOrderManufactureVO.balanceMode;
                    tStr[5] = tGSOrderManufactureVO.deliverGoodsId;
                    tStr[6] = tGSOrderManufactureVO.signinDate;
                    tStr[7] = tGSOrderManufactureVO.signinPerson;
                    tStr[8] = tGSOrderManufactureVO.deliverGoodsAddr;
                    tStr[9] = tGSOrderManufactureVO.deliveryMan;
                    tStr[10] = tGSOrderManufactureVO.deliverGoodsPhone;
                    tStr[11] = tGSOrderManufactureVO.signinExplain;

                    tStr[12] = tGSOrderManufactureVO.concentricityId;
                    tStr[13] = tGSOrderManufactureVO.manufactureId;
                    tStr[14] = tGSOrderManufactureVO.manufactureName;
                    tStr[15] = tGSOrderManufactureVO.orderCount;
                    tStr[16] = tGSOrderManufactureVO.spec == null ? "" : tGSOrderManufactureVO.spec;
                    tStr[17] = tGSOrderManufactureVO.type == null ? "" : tGSOrderManufactureVO.type;
                    tStr[18] = tGSOrderManufactureVO.brand == null ? "" : tGSOrderManufactureVO.brand;
                    tStr[19] = tGSOrderManufactureVO.quantUnit == null ? "" : tGSOrderManufactureVO.quantUnit;
                    tStr[20] = StringUtils.formatEDouble(tGSOrderManufactureVO.signinPrice, 4);
                    tStr[21] = tGSOrderManufactureVO.providerName;
                    tStr[22] = tGSOrderManufactureVO.deptName;
                    tStr[23] = tGSOrderManufactureVO.notes;
                    tStr[24] = tGSOrderManufactureVO.balanceCategory;
                    tStr[25] = tGSOrderManufactureVO.mode;
                    tStr[26] = DefineDic.getBalanceMode(tGSOrderManufactureVO.mode);
                    tList.add(tStr);
                }
            }
        } catch (GSException ge) {
            throw ge;
        } catch (Exception e) {
            GSLogWriter.error(this, e.toString());
            throw new GSException(GSException.E10042, GSException.E10042_MSG);
        }
        return tList;

    }

    /**
     * 取得待确认应急采购订单
     * 
     * @param aVO
     *            查询参数VO
     * @param aList
     *            可查询组织
     * @param aMap1
     *            二级产品种类
     * @param aMap2
     *            三级产品种类
     * @param pageNo
     *            页号
     * @param pageSize
     *            页大小
     * @return
     * @throws GSException
     */
    public ArrayList getConfirmableEmergyOrder(GSBusEmergencyOrderQueryVO aVO, ArrayList aList, HashMap aMap1, HashMap aMap2, int pageNo, int pageSize)
            throws GSException {
        ArrayList tRs = new ArrayList();
        GSTempOrderDAO tOrderDAO = new GSTempOrderDAO();
        ArrayList tList = tOrderDAO.queryConfirmableEmergyOrder(aVO, aList, aMap1, aMap2, pageNo, pageSize);
        if (tList.size() > 0) {
            for (int i = 0; i < tList.size(); i++) {
                String[] tStr = new String[20];
                GSBusEmergencyOrderQueryVO tVO = (GSBusEmergencyOrderQueryVO) tList.get(i);
                tStr[0] = tVO.deliverGoodsId;
                tStr[1] = tVO.type;
                tStr[2] = tVO.orderDeptName;
                tStr[3] = tVO.concentricityId;
                tStr[4] = tVO.manufactureName;
                tStr[5] = tVO.isTradeFlatManuf;
                tStr[6] = tVO.manufSpec;
                tStr[7] = tVO.manufType;
                tStr[8] = tVO.manufBrand;
                tStr[9] = tVO.providerName;
                tStr[10] = StringUtils.formatEDouble(tVO.orderCount, 2);
                tStr[11] = tVO.quantUnit;
                tStr[12] = StringUtils.formatEDouble(tVO.goodUnitprice, 4);
                tStr[13] = StringUtils.formatEDouble(tVO.signCount, 2);
                tStr[14] = StringUtils.formatEDouble(tVO.signPrice, 4);
                tStr[15] = tVO.isTradeFlatProvider;
                tStr[16] = tVO.providerId;
                tStr[17] = tVO.orderDetailId;
                tStr[18] = tVO.orderTempId;
                tStr[19] = tVO.mode;
                tRs.add(tStr);
            }
        }
        return tRs;
    }

    /**
     * 应急采购确认
     * 
     * @param aList
     *            待确认采购单
     * @param aOperBean
     *            操作员信息
     * @param aNewStatus
     *            采购单确认后状态
     * @return
     * @throws GSException
     */
    public String tempOrderExeConfirm(ArrayList aList, GSOperatorBean aOperBean, String aNewStatus) throws GSException {
        boolean tFlag = false;
        Connection tConn = null;
        GSTempOrderDAO tempDAO = new GSTempOrderDAO();
        GSOrderDAO tOrderDAO = new GSOrderDAO();
        GSOrderDetailDAO tOrderDtlDAO = new GSOrderDetailDAO();
        int ok = 0;
        int err = 0;
        String msg = "";
        String tRs = "";
        BigDecimal tTotal = new BigDecimal("0");
        int cou = 0;

        try {
            tConn = tempDAO.getConnetion();
            tConn.setAutoCommit(false);
            for (int i = 0; i < aList.size(); i++) {
                GSBusEmergencyOrderConfirmVO tVO = (GSBusEmergencyOrderConfirmVO) aList.get(i);
                GSTempOrderBean tBean = tempDAO.queryTempOrderDetail(tVO, tConn);
                if ("2".equals(tVO.isTradeFlatManuf)) {
                    String count = String.valueOf(tBean.getOrderCount());
                    tTotal = tTotal.add(new BigDecimal(count));
                    cou++;
                }
                
            }
            for (int i = 0; i < aList.size(); i++) {
                GSBusEmergencyOrderConfirmVO tVO = (GSBusEmergencyOrderConfirmVO) aList.get(i);
                GSTempOrderBean tBean = tempDAO.queryTempOrderDetail(tVO, tConn);
                tBean.setOrderDetailStatus(aNewStatus);
                tBean.setSignInCount(tVO.signCount);
                tBean.setSignInPrice(tVO.signPrice);
                tFlag = tempDAO.updateTempOrderDetail(tBean, GSBaseConstants.TEMP_ORDER_DETAIL_UNCOFIRM, tConn);
                if (tFlag) {
                    ArrayList tempList = new ArrayList();
                    int tNotInsertFlag = 0;
                    GSOrderBean tOrderBean = new GSOrderBean();
                    GSOrderDetailBean tOrderDetailBean = new GSOrderDetailBean();
                    // 判断在本次确认中是否已有相同的订单被插入DB
                    if (tempList.size() > 0) {
                        tNotInsertFlag = 0;
                        for (int j = 0; j < tempList.size(); j++) {
                            GSOrderBean tempBean = (GSOrderBean) tempList.get(j);
                            if (tBean.getOrderTempId().equals(tempBean.getGs_order_tempid())) {
                                tNotInsertFlag++;
                            }
                        }
                    }
                    String tCont = "";
                    if (aNewStatus.equals(GSBaseConstants.TEMP_ORDER_DETAIL_ADJCONFIRM)) {
                        tCont = "应急采购调整确认录入";
                    } else if (aNewStatus.equals(GSBaseConstants.TEMP_ORDER_DETAIL_DIRCONFIRM)) {
                        tCont = "应急采购直接确认录入";
                    }
                    if (tNotInsertFlag == 0) {
                        GSLogWriter.info("tempid=" + tBean.getOrderTempId());
                        GSOrderBean tOrderBean2 = tOrderDAO.queryOrder(tBean.getOrderTempId());
                        // 判断DB中是否已有相同的订单，若没有则插入新数据，若有则不操作
                        if (tOrderBean2 == null) {
                            tOrderBean.setGs_order_tempid(tBean.getOrderTempId());
                            tOrderBean.setGs_order_category(GSBaseConstants.ORDER_CATEGORY_1);
                            tOrderBean.setGs_order_status(GSBaseConstants.ORDER_DELIVERY_CONFIRM);
                            tOrderBean.setGs_workcorp_id(tBean.getWorkcorpId());
                            tOrderBean.setGs_deliver_goods_addr(tBean.getDeliverGoodsAddr());
                            tOrderBean.setGs_lastmodifer_id(aOperBean.getGs_oper_id());
                            tOrderBean.setGs_lastmodify_contents(tCont);
                            tOrderBean.setGs_lastmodify_date(DateUtil.formateDateTime(DateUtil.getCurrentTime("DT", "AD")));
                            tOrderBean.setGs_balance_mode(tBean.getBalanceMode());
                            tOrderBean.setGs_deliver_mode(tBean.getDeliverMode());
                            tOrderBean.setGs_notes(tBean.getNotes());
                            tOrderBean.setGs_order_create_date(tBean.getCreateTime());
                            tOrderBean.setGs_recorder_id(tBean.getRecorderid());
                            tOrderBean.setGs_order_contact_name(tBean.getOrdercontactname());
                            tOrderBean.setGs_order_contact_phone(tBean.getOrdercontactphone());
                            tFlag = tOrderDAO.insertOrderFromTemp(tOrderBean, tConn);
                            tempList.add(tOrderBean);// 将该笔已插入DB的的订单放入临时集合
                        } else {
                            GSLogWriter.info(GSException.E30002_MSG);
                        }
                    } else {
                        GSLogWriter.info(GSException.E30002_MSG);
                    }
                    // 插订单明细表
                    GSLogWriter.info("tempid=" + tBean.getOrderDetailId());
                    tOrderDetailBean.setGs_order_temp_id(tBean.getOrderTempId());
                    tOrderDetailBean.setGs_order_detail_id(tBean.getOrderDetailId());
                    tOrderDetailBean.setGs_order_detail_status(GSBaseConstants.ORDER_DELIVERY_CONFIRM);
                    tOrderDetailBean.setGs_concentricity_id(tBean.getConcentricityId());
                    tOrderDetailBean.setGs_manufacture_id(tBean.getManufactureId());
                    tOrderDetailBean.setGs_order_count(tBean.getOrderCount());
                    tOrderDetailBean.setGs_provider_id(tBean.getProviderId());
                    tOrderDetailBean.setGs_deliver_goods_id(tBean.getDeliverGoodsId());
                    tOrderDetailBean.setGs_goods_unitprice(tBean.getSignInPrice());
                    tOrderDetailBean.setGs_signin_count(tBean.getSignInCount());
                    tOrderDetailBean.setGs_signin_date(tBean.getSignInDate());
                    tOrderDetailBean.setGs_signin_explain(tBean.getSignInExplain());
                    tOrderDetailBean.setGs_signin_person(tBean.getSignInPerson());
                    tOrderDetailBean.setGs_signin_time(tBean.getSignInTime());
                    tOrderDetailBean.setGs_is_balanced(GSBaseConstants.UNBALANCE_STATUS);
                    tOrderDetailBean.setGs_is_prov_balanced(GSBaseConstants.UNBALANCE_STATUS);
                    tOrderDetailBean.setGs_lastmodifer_id(aOperBean.getGs_oper_id());
                    tOrderDetailBean.setGs_lastmodify_contents(tCont);
                    tOrderDetailBean.setGs_deliver_goods_counts(tBean.getSignInCount());// 配送数量等于签收数量
                    tOrderDetailBean.setGs_deliver_goods_date(tBean.getSignInDate());
                    tOrderDetailBean.setGs_deliver_goods_time(tBean.getSignInTime());
                    tFlag = tOrderDtlDAO.insertOrderDetailFromTemp(tOrderDetailBean, tConn);
                }
                if (tFlag) {
                    if ("2".equals(tVO.isTradeFlatManuf)) {
                        tConn.commit();
                        ok++;
                    } else {
                        // 执行订单提交
                        tRs = tempOrderSubmitToApep(tBean, aOperBean, String.valueOf(cou), tTotal.toString(), i);
                        if (tRs.equals("1")) {
                            tConn.commit();
                            ok++;
                        } else {
                            tConn.rollback();
                            err++;
                        }
                    }
                }
            }
            if (err==0) {
                msg="共"+ok+"笔订单确认成功。";
            }else if (err>0) {
                msg="共"+ok+"笔订单确认成功,有"+err+"笔订单系统异常确认失败。";
            }
        } catch (GSException ge) {
            try {
                tConn.rollback();
            } catch (SQLException se) {
                se.printStackTrace();
            }
            throw ge;
        } catch (Exception e) {
            try {
                tConn.rollback();
            } catch (SQLException sqle) {
                sqle.printStackTrace();
            }
            GSLogWriter.error(this, e.toString());
            throw new GSException(GSException.E30001, GSException.E30001_MSG);
        } finally {
            try {
                if (tConn != null) {
                    tConn.setAutoCommit(true);
                    tConn.close();
                }
            } catch (SQLException se) {
                se.printStackTrace();
            }
        }
        return msg;
    }

    /**
     * 提交应急采购交货确认
     * 
     * @param aList
     *            待提交采购单集
     * @param aOperBean
     *            操作员对象
     * @return
     * @throws GSException
     */
    private String tempOrderSubmitToApep(GSTempOrderBean tOrderManufVO, GSOperatorBean aOperBean, String count, String total, int i) throws GSException {
        String tRs = "";
        try {
            // 读取采购网给巴士物资的编码
            String tPurCode = GSSystemConfigurator.getParam("gs.purcode");
            String tWorkDT = DateUtil.formateDateTime(DateUtil.getCurrentTime("DT", "AD"));

            // 组装要发送到采购网的内容
            ParameterFactory pf = new ParameterFactory();
            pf.addParam("Action", "SubmitOrder");
            pf.addParam("Count", count);
            pf.addParam("Total", total);
            String purName = "";
            purName = getWorkCorp(tOrderManufVO.getWorkcorpId());
            pf.addParam("CusOrderItemCode_" + i, tOrderManufVO.getOrderDetailId());
            pf.addParam("ProductID_" + i, tOrderManufVO.getManufactureId());
            pf.addParam("CusItemCode_" + i, tOrderManufVO.getConcentricityId());
            pf.addParam("Price_" + i, String.valueOf(tOrderManufVO.getSignInPrice()));
            pf.addParam("Qty_" + i, String.valueOf(tOrderManufVO.getOrderCount()));
            pf.addParam("SendMode_" + i, GSBaseManager.getDictioanryName(tOrderManufVO.getDeliverMode()));
            pf.addParam("PayMode_" + i, GSBaseManager.getDictioanryName(tOrderManufVO.getBalanceMode()));

            String deliverGoodsDate = "";
            if (tOrderManufVO.getOrderCategory().equals(GSBaseConstants.ORDER_CATEGORY_1)) {
                deliverGoodsDate = tOrderManufVO.getCreateTime(); // 出货单以订单创建日期为送货日期时间
            } else if (tOrderManufVO.getOrderCategory().equals(GSBaseConstants.ORDER_CATEGORY_2)) {
                deliverGoodsDate = tOrderManufVO.getSignInDate() // 补单以签收日期时间为送货日期时间
                        + GSBaseManager.getDeliverGoodsTime(tOrderManufVO.getSignInTime());
            }
            pf.addParam("SendRequire_" + i, deliverGoodsDate);
            pf.addParam("Address_" + i, tOrderManufVO.getDeliverGoodsAddr());
            pf.addParam("LinkPerson_" + i, tOrderManufVO.getOrdercontactname());
            pf.addParam("LinkPhone_" + i, tOrderManufVO.getOrdercontactphone());
            pf.addParam("CusCode_" + i, tPurCode);
            pf.addParam("PurName_" + i, purName);
            String remark = tOrderManufVO.getNotes();
            pf.addParam("Remark_" + i, remark);
            pf.addParam("CreateTime_" + i, tWorkDT);
            pf.addParam("SubmitPerson_" + i, aOperBean.getGs_oper_name());
            pf.addParam("SendCode_" + i, tOrderManufVO.getDeliverGoodsId());
            pf.addParam("ReceiveDate_" + i, (tOrderManufVO.getSignInDate() == null ? "" : tOrderManufVO.getSignInDate()));
            pf.addParam("ReceiveQty_" + i, String.valueOf(tOrderManufVO.getSignInCount()));
            pf.addParam("ReceivePerson_" + i, (tOrderManufVO.getSignInPerson() == null ? "" : tOrderManufVO.getSignInPerson()));
            GSLogWriter.debug(this, "传送内容" + pf.getStrStream());
            // 取得配置文件中服务端IP和端口参数
            String tIP = GSSystemConfigurator.getParam("gs.ip");
            String tPort = GSSystemConfigurator.getParam("gs.port");
            // 连接服务端
            GSClientSocket tClientSocket = new GSClientSocket(tIP, Integer.parseInt(tPort));

            // 发送订单信息到采购网
            tRs = tClientSocket.sendContents(pf.getStrStream());
        } catch (GSException ge) {
            throw ge;
        } catch (Exception e) {
            GSLogWriter.error(this, e.toString());
            throw new GSException(GSException.E00001, GSException.E00001_MSG);
        }
        return tRs;
    }

    /**
     * 删除应急采购单
     * 
     * @param aList
     *            待删除采购单编号集
     * @return
     * @throws GSException
     */
    public boolean delTempOrder(ArrayList aList) throws GSException {
        boolean tFlag = false;
        Connection tConn = null;
        GSTempOrderDAO tempDAO = new GSTempOrderDAO();
        try {
            tConn = tempDAO.getConnetion();
            tConn.setAutoCommit(false);
            for (int i = 0; i < aList.size(); i++) {
                GSBusEmergencyOrderConfirmVO tVO = (GSBusEmergencyOrderConfirmVO) aList.get(i);
                tFlag = tempDAO.deleteTempOrderDetail(tVO, tConn);
                if (!tFlag) {
                    tConn.rollback();
                    break;
                }
            }
            if (tFlag) {
                tConn.commit();
            }
        } catch (GSException ge) {
            throw ge;
        } catch (Exception e) {
            GSLogWriter.error(this, e.toString());
            throw new GSException(GSException.E00001, GSException.E00001_MSG);
        } finally {
            try {
                if (tConn != null) {
                    tConn.setAutoCommit(true);
                    tConn.close();
                }
            } catch (SQLException se) {
                se.printStackTrace();
            }
        }
        return tFlag;
    }

    /**
     * 查询应急采购单明细
     * 
     * @param aOrderId
     *            订单编号
     * @param aOrderDetailId
     *            订单明细编号
     * @param aDeliverGoodsId
     *            送货地址编号
     * @return
     * @throws GSException
     */
    public HashMap queryTempOrderDetail(String aOrderId, String aOrderDetailId, String aDeliverGoodsId) throws GSException {
        HashMap tMap = new HashMap();
        ArrayList tRs = new ArrayList();
        GSTempOrderDAO tDAO = new GSTempOrderDAO();
        Connection tConn = null;
        try {
            tConn = tDAO.getConnetion();
            // 执行查询
            ArrayList tList = tDAO.queryTempOrderDetail(aOrderId, tConn);
            if (tList.size() > 0) {
                // 封装查询结果
                for (int i = 0; i < tList.size(); i++) {
                    String tStr[] = new String[18];
                    GSBusEmergencyOrderConfirmDetailVO tVO = (GSBusEmergencyOrderConfirmDetailVO) tList.get(i);
                    tStr[0] = tVO.orderDetailId;
                    tStr[1] = tVO.concentricityId;
                    tStr[2] = tVO.manufName;
                    tStr[3] = tVO.manufSpec;
                    tStr[4] = tVO.manufType;
                    tStr[5] = tVO.manufBrand;
                    tStr[6] = StringUtils.formatEDouble(tVO.orderCount, 2);
                    tStr[7] = StringUtils.formatEDouble(tVO.signCount, 2);
                    tStr[8] = tVO.quantUnit;
                    tStr[9] = tVO.providerName;
                    tStr[10] = StringUtils.formatEDouble(tVO.unitPrice, 4);
                    tStr[11] = StringUtils.formatEDouble(tVO.signPrice, 4);
                    tStr[12] = tVO.isTradeFlatManuf;
                    tStr[13] = tVO.isTradeFlatProvider;
                    tStr[14] = tVO.providerId;
                    tRs.add(tStr);
                }
                tMap.put("list", tRs);
            }
            GSBusEmergencyOrderConfirmVO tCofmVO = new GSBusEmergencyOrderConfirmVO();
            tCofmVO.orderDetailId = aOrderDetailId;
            tCofmVO.deliverGoodsId = aDeliverGoodsId;
            GSTempOrderBean tOrderBean = tDAO.queryTempOrderDetail(tCofmVO, tConn);
            tMap.put("curTempOrderBean", tOrderBean);
        } catch (Exception e) {
            GSLogWriter.error(this, e.toString());
            throw new GSException(GSException.E00001, GSException.E00001_MSG);
        } finally {
            try {
                if (tConn != null)
                    tConn.close();
            } catch (SQLException se) {
                se.printStackTrace();
            }
        }
        return tMap;
    }

    public String getWorkCorp(String orgid) throws GSException {
        String rt = "";
        if (orgid == null) {
            GSLogWriter.error("WorkCorp ID is null");
            return rt;
        }
        if (orgid.length() != 4) {
            GSLogWriter.error("WorkCorp ID length isn't 4");
            return rt;
        }
        GSOrganizationDAO orgdao = new GSOrganizationDAO();
        if (orgid.substring(2, 4).equals("00")) {
            rt = orgdao.queryOrgName(orgid);
        } else {
            rt = orgdao.getParentOrg(orgid).getGs_org_name();
        }

        return rt;
    }

}
